<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Flask & ECharts 大屏</title>
    <!-- 引入 ECharts 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.3.3/echarts.min.js"></script>
    <style>

        .chart-container {
            width: 45%;
            float: left;
            margin: 1%;
        }
    </style>
</head>
<body>

    <p>{{ chart1_data.categories|tojson|safe }}</p>

   <div id="main" style="width: 600px;height:400px;"></div>

    <div class="chart-container">
        <div id="chart1" style="width: 100%;height:400px;"></div>
    </div>
    <div class="chart-container">
        <div id="chart2" style="width: 100%;height:400px;"></div>
    </div>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('chart1'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: 'ECharts 示例'
            },
            tooltip: {},
            legend: {
                data:['销量']
            },
            xAxis: {
                 data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [120, 200, 150, 80, 70, 110, 130],
            }]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

    {#
        var chart1 = echarts.init(document.getElementById('chart1'));
        var option1 = {
            xAxis: {
                data: {{ chart1_data.categories|tojson|safe }}
            },
            yAxis: {},
            series: [{
                data: {{ chart1_data.data|tojson|safe }},
                type: 'bar'
            }]
        };
        chart1.setOption(option1);
        #}

        var chart2 = echarts.init(document.getElementById('chart2'));
        var option2 = {
            series: [{
                type: 'pie',
                radius: '55%',
                data: {{ chart2_data.data|tojson|safe }},
                label: {
                    show: true,
                    formatter: '{b}: {c} ({d}%)'
                }
            }]
        };
        chart2.setOption(option2);
    </script>


</body>
</html>